import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomePage/HomeView.vue'
import Login from '@/views/LoginPage/LoginView.vue'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    children: [
      {
        path: "/zong",
        name: "zong",
        component: () => import('@/views/HomePage/components/Zongyemian.vue'),
      },
      {//我的订单
        path: "/myorder",
        name: "myorder",
        component: () => import('@/views/MyOrderPage/MyOrderView.vue'),
        children: [
          {//个人中心
            path: "/myorder/personalcenter",
            name: "personalcenter",
            component: () => import('@/views/MyOrderPage/components/PersonalCenterCom.vue'),
          },
          {//我的订单中的交易管理下面的我的订单
            path: "/myorder/myordercom",
            name: "myordercom",
            component: () => import('@/views/MyOrderPage/components/MyOrderCom.vue'),
          }
        ],
        beforeEnter(to, from, next) {
          if (localStorage.getItem('userName') != null) {
            next()
          } else {
            next('/')
          }
        },
      },
      {//首页
        path: "/home/homes",
        name: "homecom",
        component: () => import('@/views/HomePage/components/HomeCom.vue')
      },
      {//详情页
        path: "/home/detailpage",
        name: "detailpage",
        component: () => import('@/views/DetailPage/detailPageView.vue')
      },
      {//商品品牌，颜色，产地尺寸等内容选择页面
        path: "/home/detailslist",
        name: "detailslist",
        component: () => import('@/views/ProductDetailsListPage/DetailsListView.vue')
      },
      {//购物车
        path: "/home/shoppingcar",
        name: "shoppingcar",
        component: () => import('@/views/ShoppingCar/ShopPingView.vue'),
      },
      {//购物车填写订单
        path: "/home/shoppingcar/shoppingorder",
        name: "shoppingorder",
        component: () => import('@/views/ShoppingCar/components/ShoppingOrderCom.vue'),
      },
      {//购物车提交订单
        path: "/home/shopping/submitorder",
        name: "submitorder",
        component: () => import('@/views/ShoppingCar/components/SubmitOrderCom.vue'),
      }
    ],
  },
  {//登录页面
    path: '/',
    name: 'login',
    component: Login
  },
  {//支付宝支付页面
    path: "/home/shopping/paybyalipay",
    name: "paybyalipay",
    component: () => import('@/views/ShoppingCar/components/PayByAlipay.vue'),
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
